package com.example.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.mapper.WarningInfoMapper;
import com.example.demo.entity.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@Controller
public class CheckWarningController {
    @Autowired
    private WarningInfoMapper wm;
    @RequestMapping("/checkwarning")
    public void updateWarning(HttpServletRequest request, HttpServletResponse response) throws IOException {
        int warningid=Integer.valueOf(request.getParameter("warningid"));
        int warningtype=Integer.valueOf(request.getParameter("warningtype"));
        String warningdetail=request.getParameter("warningdetail");
        Date date = new Date(System.currentTimeMillis());
        int n=wm.checkWarningInfo(warningtype,warningdetail,date,1,warningid);
        if(n>0){
            response.getWriter().write(JSONObject.toJSONString(Message.success("Warning info check success")));
        }else response.getWriter().write(JSONObject.toJSONString(Message.failure("Warninginfo check failure")));
    }
}
